
//% color="#6a32fa" iconWidth=50 iconHeight=40
namespace blinker {

    //% block="blinker初始化 WiFi连接[SSID][PSWD][AUTH]" blockType="command"
    //% SSID.shadow="string"   SSID.defl="yourSSID123"
    //% PSWD.shadow="string"   PSWD.defl="yourPASSWD"
    //% AUTH.shadow="string"   AUTH.defl="6c4013a35bdb"
    export function init(parameter: any, block: any) {
        let ssid=parameter.SSID.code;
        let pswd=parameter.PSWD.code;
        let auth=parameter.AUTH.code;

        
        Generator.addInclude("addincludeblinkeraduinonone", "#include <Blinker_AUDIO_NONE_NONE_NONE_NONE_NONE.h>");
        Generator.addSetup(`blinkinit`,`Blinker.begin(${auth},${ssid},${pswd});`)
 
    }
        
    //% block="功能配置[AITYPE][AIMODE]" blockType="command"
    //% AITYPE.shadow="dropdown"    AITYPE.options="AITYPE" 
    //% AIMODE.shadow="dropdown"    AIMODE.options="AIMODE" 
    export function aivoicesetup(parameter: any, block: any) {
        let aitype=parameter.AITYPE.code;
        let aimode=parameter.AIMODE.code;
        Generator.addInclude("addincludeai", `#include <Blinker_AUDIO_${aitype}_${aimode}.h>`);

    }

    //% block="blinker运行" blockType="command"
    export function run(parameter: any, block: any) {

        Generator.addCode(`Blinker.run();`)
 
    }

    //% block="blinker等待[NUM]毫秒" blockType="command"
    //% NUM.shadow="number"   NUM.defl="2000"
    export function delay(parameter: any, block: any) {
        let num=parameter.NUM.code;
        Generator.addCode(`Blinker.delay(${num});`)
    
    }

    //% block="---"
    export function noteSep1() {

    }

    //% block="调试控件打印[STR]" blockType="command"
    //% STR.shadow="string"   STR.defl="hello"
    export function debug(parameter: any, block: any) {
        let str=parameter.STR.code;
        Generator.addCode(`Blinker.print(${str});`)
    
    }
    
    //% block="---"
    export function noteSep2() {

    }

    //% block="当按钮组件[BTO]键名[BTN]接收到数据" blockType="hat"
    //% BTO.shadow="string"   BTO.defl="button1"
    //% BTN.shadow="string"   BTN.defl="btn-abc"
    export function buttonrec(parameter: any, block: any) {
        let bto=parameter.BTO.code;
        let btn=parameter.BTN.code;

        bto = bto.replace(/"/g,"");//去除引号
         

        Generator.addObject(`BlinkerButton`, `BlinkerButton`, `${bto}(${btn});`);

        Generator.addSetup(`buttonrec_callback_setup`,`${bto}.attach(${bto}_callback);`)

        Generator.addEvent(`buttonrec_callback_event`, "void", `${bto}_callback`, "const String & state");
    }
    //% block="读取按钮组件返回的数据" blockType="reporter"
    export function buttondata(parameter: any, block: any) {
        Generator.addCode(["state", Generator.ORDER_UNARY_POSTFIX])
    
    }

    //% block="按钮[BTO]打印[STR]" blockType="command"
    //% BTO.shadow="string"   BTO.defl="button1"
    //% STR.shadow="string"   STR.defl="on"
    export function buttonprint(parameter: any, block: any) {
        let bto=parameter.BTO.code;
        let str=parameter.STR.code;

        bto = bto.replace(/"/g,"");//去除引号


        Generator.addCode(`${bto}.print(${str});`)
    
    }

    //% block="按钮[BTO]文字修改为[STR]" blockType="command"
    //% BTO.shadow="string"   BTO.defl="button1"
    //% STR.shadow="string"   STR.defl="on"
    export function buttontext(parameter: any, block: any) {
        let bto=parameter.BTO.code;
        let str=parameter.STR.code;

        bto = bto.replace(/"/g,"");//去除引号


        Generator.addCode(`${bto}.text(${str});`)
    
    }
    //% block="---"
    export function noteSep3() {

    }
    //% block="当接收到数据" blockType="hat"

    export function dataRead(parameter: any, block: any) {

        Generator.addSetup(`dataRead_callback`,`Blinker.attachData(dataRead);`)

        Generator.addEvent("dataRead_callback_addEvent", "void", `dataRead`, "const String & data");
    }
    //% block="读取返回的数据" blockType="reporter"
    export function dataReadstate(parameter: any, block: any) {
        Generator.addCode(["data", Generator.ORDER_UNARY_POSTFIX])
    
    }
    //% block="---"
    export function noteSep4() {

    }



    //% block="语音助手[AIRECTYPE]多路开关控制" blockType="hat"
    //% AIRECTYPE.shadow="dropdown"    AIRECTYPE.options="AIRECTYPE" 
    export function yuyincallback(parameter: any, block: any) {
        let type=parameter.AIRECTYPE.code;
        Generator.addSetup(`yuyincallback`,`${type}.attachPowerState(${type}state);`)
        Generator.addEvent("yuyincallbackaddEvent", "void", `${type}data`, "const String & state, uint8_t num");
    }

    //% block="读取语音助手返回的数据" blockType="reporter"
    export function yuyindataReadstate(parameter: any, block: any) {
        Generator.addCode(["state", Generator.ORDER_UNARY_POSTFIX])
    
    }
    //% block="读取语音助手返回的编号" blockType="reporter"
    export function yuyindataReadnum(parameter: any, block: any) {
        Generator.addCode(["num", Generator.ORDER_UNARY_POSTFIX])
    
    }
    //% block="---"
    export function noteSep5() {

    }



    //% block="天猫精灵[ALRECCZTYPE]操作" blockType="hat"
    //% ALRECCZTYPE.shadow="dropdown"    ALRECCZTYPE.options="ALRECCZTYPE" 
    export function tianmaocallback(parameter: any, block: any) {
        let type=parameter.ALRECCZTYPE.code;
        Generator.addSetup(`tianmaocallback`,`BlinkerAliGenie.${type}(${type}data);`)
        Generator.addEvent("tianmaocallbackaddEvent", "void", `${type}data`, "const String & data");
    }


    //% block="小爱同学[MIORECCZTYPE]操作" blockType="hat"
    //% MIORECCZTYPE.shadow="dropdown"    MIORECCZTYPE.options="MIORECCZTYPE" 
    export function xiaoaicallback(parameter: any, block: any) {
        let type=parameter.MIORECCZTYPE.code;
        Generator.addSetup(`xiaoaicallback`,`BlinkerMIOT.${type}(${type}data);`)
        Generator.addEvent("xiaoaicallbackaddEvent", "void", `${type}data`, "const String & data");
    }

    
    //% block="百度小度[BDRECCZTYPE]操作" blockType="hat"
    //% BDRECCZTYPE.shadow="dropdown"    BDRECCZTYPE.options="BDRECCZTYPE" 
    export function bdcallback(parameter: any, block: any) {
        let type=parameter.BDRECCZTYPE.code;
        Generator.addSetup(`bdcallback`,`BlinkerDuerOS.${type}(${type}data);`)
        Generator.addEvent("bdcallbackaddEvent", "void", `${type}data`, "const String & data");
    }
 
    //% block="读取音箱返回的数据" blockType="reporter"
    export function readcallbackstate(parameter: any, block: any) {
        Generator.addCode(["data", Generator.ORDER_UNARY_POSTFIX])
    
    }

    //% block="天猫精灵[AILIGET]" blockType="reporter"
    //% AILIGET.shadow="dropdown"   AILIGET.options="AILIGET" 
    export function aligetdata(parameter: any, block: any) {
        let get=parameter.AILIGET.code;

        Generator.addCode([`${get}`, Generator.ORDER_UNARY_POSTFIX])
    
    }

    //% block="小爱同学[MIOTGET]" blockType="reporter"
    //% MIOTGET.shadow="dropdown"   MIOTGET.options="MIOTGET" 
    export function miogetdata(parameter: any, block: any) {
        let get=parameter.MIOTGET.code;

        Generator.addCode([`${get}`, Generator.ORDER_UNARY_POSTFIX])
    
    }

    //% block="百度小杜[BDGET]" blockType="reporter"
    //% BDGET.shadow="dropdown"   BDGET.options="BDGET" 
    export function bdgetdata(parameter: any, block: any) {
        let get=parameter.BDGET.code;

        Generator.addCode([`${get}`, Generator.ORDER_UNARY_POSTFIX])
    
    }


    //% block="语音控制反馈:[AIRECTYPE]反馈[RECSTATE][MESS]" blockType="command"
    //% AIRECTYPE.shadow="dropdown"    AIRECTYPE.options="AIRECTYPE" 
    //% RECSTATE.shadow="dropdown"    RECSTATE.options="RECSTATE" 
    //% MESS.shadow="string"   MESS.defl="on"
    export function buttontextrec(parameter: any, block: any) {
        let aitype=parameter.AIRECTYPE.code;
        let state=parameter.RECSTATE.code;
        let mess=parameter.MESS.code;

        Generator.addCode(`${aitype}.${state}(${mess});`)
        Generator.addCode(`${aitype}.print();`)
    
    }

    //% block="语音控制反馈单:[AIRECTYPE]反馈[RECSTATE][MESS]" blockType="command"
    //% AIRECTYPE.shadow="dropdown"    AIRECTYPE.options="AIRECTYPE" 
    //% RECSTATE.shadow="dropdown"    RECSTATE.options="RECSTATE" 
    //% MESS.shadow="string"   MESS.defl="on"
    export function buttontextrecdan(parameter: any, block: any) {
        let aitype=parameter.AIRECTYPE.code;
        let state=parameter.RECSTATE.code;
        let mess=parameter.MESS.code;

        Generator.addCode(`${aitype}.${state}(${mess});`)
    
    }
    


}
